

package examples.radio;

import commandz.cli.*;
import java.util.Collection;


/**
 *  Example of a Command-implementation which interacts with the
 *  Interpreter itself.
 */
public final class HelpCommand implements Command
{
    private Interpreter interpreter;


    /**
     *  Initializes a new HelpCommand for use with the given Interpreter.
     *
     *  @param interpreter The interpreter to use.
     */
    public HelpCommand(Interpreter interpreter)
    {
        this.interpreter = interpreter;
    }


    /**
     *  Returns the name of this Command.
     *
     *  @see Command
     */
    public String getName()
    {
        return "help";
    }


    /**
     *  Returns a brief description of this Command.
     *
     *  @see Command
     */
    public String getDescription()
    {
        return "Provides information about the available commands.";
    }


    /**
     *  Publishes .. nothing.
     */
    public void publishParameters(Collection<Parameter> params)
    {
    }


    /**
     *  Executes this Command.
     *
     *  @see Command
     */
    public void execute()
    {
        System.out.println("Available commands:\n");

        for (Command cmd : this.interpreter.getCommands())
            System.out.printf("%10s - %s\n", cmd.getName(), cmd.getDescription());
        
        System.out.println();
    }
}
